package com.nandi.deviceinstall.model

import com.nandi.deviceinstall.bean.*
import com.nandi.deviceinstall.contract.EquipmentBindContract
import com.nandi.deviceinstall.net.RetrofitClient
import com.nandi.deviceinstall.net.dto.BindAddDTO
import com.nandi.deviceinstall.net.dto.BindUpdateDTO
import io.reactivex.Flowable
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File

class EquipmentBindModel : EquipmentBindContract.Model {
    override fun executeListDisName(token: String, disasterName: String, town: String): Flowable<DisNameBean> {
        return apiService.listDisName(token, disasterName, town)
    }

    override fun executeUpdateBind(token: String, params: BindUpdateDTO): Flowable<BaseObjectBean<BindAddBean>> {
        return apiService.updateBind(token, params)
    }

    private val apiService = RetrofitClient.getInstance()!!.api!!

    override fun executeRemoveDevPicFile(token: String, path: String): Flowable<DevPicRemoveBean> {
        return apiService.removeDevPicFile(token, path)
    }

    override fun executeAddBind(token: String, params: BindAddDTO): Flowable<BaseObjectBean<BindAddBean>> {
        return apiService.addBind(token, params)
    }

    override fun executeUploadDevPic(token: String, file: File): Flowable<UploadPicBean> {
        val picFile = RequestBody.create(MediaType.parse("image/*"), file)
        val createFormData = MultipartBody.Part.createFormData("file", file.name, picFile)
        return apiService.uploadDevPic(token, createFormData)
    }

    override fun executeDisNum(token: String, disName: String, areaCode: String): Flowable<DisNumBean> {
        return apiService.getDisNum(token, disName, areaCode)
    }

    override fun getListDisaster(token: String, areaCode: String): Flowable<DisasterBean> {
        return apiService.listDisaster(token, areaCode)
    }

    override fun getListCity(token: String, district: String): Flowable<CityBean> {
        return apiService.listCity(token, district)
    }

    override fun getListTown(token: String, id: Int): Flowable<TownBean> {
        return apiService.listTown(token, id)
    }

    override fun getListMonitorNum(token: String, unifiedCode: String): Flowable<ListMonitorNumBean> {
        return apiService.listMonitorNum(token, unifiedCode)
    }

    override fun getListDevFactory(token: String,factory: String): Flowable<DeviceFacBean> {
        return apiService.listDevFactory(token,factory)
    }

}